package org.wu.framework.lazy.orm.core.persistence.reverse;

import org.wu.framework.core.NormalUsedString;
import org.wu.framework.lazy.orm.core.config.ReverseEngineering;
import org.wu.framework.lazy.orm.core.config.enums.WebArchitecture;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyFactory;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.feign.DefaultFeignLazyFactory;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.mvc.DefaultMVCLazyFactory;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.vue.DefaultVueFactory;

import java.io.File;

public class ReverseClassFactory {

    /**
     * describe 创建 Java class
     *
     * @param reverseClassLazyTableEndpoint ClassLazyTableEndpoint 参数
     * @return void void
     * @author Jia wei Wu
     * @date 2022/1/23 7:55 下午
     **/
    public static void createJava(ReverseClassLazyTableEndpoint reverseClassLazyTableEndpoint) {
        createJava(reverseClassLazyTableEndpoint, new ReverseEngineering());
    }


    /**
     * describe 创建 Java class
     *
     * @param reverseClassLazyTableEndpoint ClassLazyTableEndpoint 参数
     * @param reverseEngineering            逆向工程参数
     * @return void void
     * @author Jia wei Wu
     * @date 2022/1/23 3:50 下午
     **/
    public static void createJava(ReverseClassLazyTableEndpoint reverseClassLazyTableEndpoint, ReverseEngineering reverseEngineering) {

        // 写入class文件
        String resourceFilePrefix = reverseEngineering.getResourceFilePrefix();
        // 工作空间存储
        final String packageName = reverseClassLazyTableEndpoint.getPackageName();

        String target = resourceFilePrefix.split("target")[0] + "src/main/java/";

        resourceFilePrefix = target + packageName.replace(NormalUsedString.DOT, File.separator) + File.separator;


        if (WebArchitecture.WEB_MVC.equals(reverseEngineering.getWebArchitecture())) {
            DefaultMVCLazyFactory.defaultMVCLazyControllerCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultMVCLazyFactory.defaultDefaultMVCLazyServiceCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultMVCLazyFactory.defaultDefaultMVCLazyServiceImplCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultMVCLazyFactory.defaultDefaultMVCLazyMapperCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultMVCLazyFactory.defaultDefaultMVCLazyMapperXmlCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultMVCLazyFactory.defaultDefaultMVCLazyEntityCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);

        } else if (WebArchitecture.DDD_ARCHITECTURE.equals(reverseEngineering.getWebArchitecture())) {
            DefaultDDDLazyFactory.defaultDDDLazyControllerCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyApplicationCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyApplicationImplCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyAssemblerCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDefaultDDDLazyDTOCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyCommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyExcelExportCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyExcelImportCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyQueryOneCommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyQueryListCommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyStoryCommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyUpdateCommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyDomainCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyDomainRepositoryCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyInfrastructureConverterCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyInfrastructureEntityCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);

            DefaultDDDLazyFactory.defaultDDDLazyInfrastructureMapperCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyInfrastructureMapperXmlCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultDDDLazyFactory.defaultDDDLazyInfrastructurePersistenceCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            // 创建jpa
            DefaultDDDLazyFactory.defaultDDDLazyInfrastructureLazyJpaCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);

        } else if (WebArchitecture.FEIGN_API.equals(reverseEngineering.getWebArchitecture())) {
            DefaultFeignLazyFactory.defaultDefaultFeignLazyApiCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultFeignLazyFactory.defaultDefaultFeignLazyApiRpcCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultFeignLazyFactory.defaultDefaultFeignLazyAoCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultFeignLazyFactory.defaultDefaultFeignLazyAPICommandCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
            DefaultFeignLazyFactory.defaultDefaultFeignLazyAPIDTOCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        } else if (WebArchitecture.MODULE.equals(reverseEngineering.getWebArchitecture())) {
            DefaultMVCLazyFactory.defaultDefaultMVCLazyEntityCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        }

    }

    /**
     * describe 创建 Java class
     *
     * @param reverseClassLazyTableEndpoint ClassLazyTableEndpoint 参数
     * @return void void
     * @author Jia wei Wu
     * @date 2022/1/23 7:55 下午
     **/
    public static void createVue(ReverseClassLazyTableEndpoint reverseClassLazyTableEndpoint) {
        createVue(reverseClassLazyTableEndpoint, new ReverseEngineering());
    }


    /**
     * describe 创建 Java class
     *
     * @param reverseClassLazyTableEndpoint ClassLazyTableEndpoint 参数
     * @param reverseEngineering            逆向工程参数
     * @return void void
     * @author Jia wei Wu
     * @date 2022/1/23 3:50 下午
     **/
    public static void createVue(ReverseClassLazyTableEndpoint reverseClassLazyTableEndpoint, ReverseEngineering reverseEngineering) {


        // 工作空间存储
        final String packageName = reverseClassLazyTableEndpoint.getPackageName();

        // 写入Vue文件
        String resourceFilePrefix = reverseEngineering.getResourceFilePrefix() + File.separator + packageName.replace(NormalUsedString.DOT, File.separator) + File.separator;

        DefaultVueFactory.defaultVuePageCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        DefaultVueFactory.defaultVueApiCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        DefaultVueFactory.defaultVueMenuCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        DefaultVueFactory.defaultVueEditCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
        DefaultVueFactory.defaultVueUploadCreateJavaFile(reverseClassLazyTableEndpoint, reverseEngineering, resourceFilePrefix);
    }
}
